home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
program
/
ddj0897.zip
/
RCSC.ZIP
/
LIB51
/
ITOU.C
< prev
next >
Wrap
Text File
|
1997-01-12
|
625b
|
24 lines
/*
** itou -- convert nbr to unsigned decimal string of width sz
** right adjusted, blank filled; returns str
**
** if sz > 0 terminate with null byte
** if sz = 0 find end of string
** if sz < 0 use last byte for data
*/
itou(nbr, str, sz) int nbr; char str[]; int sz; {
int lowbit;
if(sz>0) str[--sz]=NULL;
else if(sz<0) sz = -sz;
else while(str[sz]!=NULL) ++sz;
while(sz) {
lowbit=nbr&1;
nbr=(nbr>>1)&32767; /* divide by 2 */
str[--sz]=((nbr%5)<<1)+lowbit+'0';
if((nbr=nbr/5)==0) break;
}
while(sz) str[--sz]=' ';
return str;
}